<?php
namespace app\index\controller;
use app\model\Admin as AdminModel;
use app\model\AdminToken as AdminTokenModel;
use app\model\Role as RoleModel;


use think\facade\Cache;
use think\captcha\Captcha;
use think\Db;


class Admin extends Base
{   
    protected $noCheckToken = ['index','read'];
    
    // 列表
    public function index(){
        $map_params = [
            ['key'=>'is_top','type'=>'=']
        ];
        $map = getSearchParam($map_params);
        if (isSearchParam('keyword_search')) {
            $map[] = ['truename','like','%'.input('keyword_search').'%'];
        }
        if (isSearchParam('start_time')) {
            $map[] = ['create_time','>=',input('start_time')];
        }
        if (isSearchParam('end_time')) {
            $map[] = ['create_time','<=',input('end_time')];
        }
        $map[] = ['status','=',1];
        // $map[] = ['type','=',1];

        $model = new AdminModel();
        $page_param = ['page'=>input('page_index',1),'list_rows'=>input('page_size',10)];
        $list = $model->field('uuid,truename,mobile,create_time,email,teacher_level,image,content,description')->where($map)->order('sort','desc')->paginate($page_param)->toarray();
        foreach ($list['data'] as $k => $vo) {
            $list['data'][$k]['role_name'] = RoleModel::where('uuid',$vo['role_uuid'])->value('name');
        }

        return apiResult('2000','获取成功',$list);
    }

    // 详情
    public function read($uuid,$lesson_date=''){
        $model = new AdminModel();
        $data = $model->field('uuid,truename,mobile,create_time,email,teacher_level,image,content,description')->where('uuid',$uuid)->find();
        if (!empty($data)) {
            if (!empty($lesson_date)) {
                $data['lesson_time'] = Db::name('orders')->where([
                    ['teacher_uuid','=',$data['uuid']],
                    ['lesson_date','=',$lesson_date],
                    ['status','<>',-1]
                ])->column('lesson_time');
            }
            // $data['role_name'] = RoleModel::where('uuid',$data['role_uuid'])->value('name');

        }
        return apiResult('2000','获取成功',$data);
    }

   


}
